perf: add SignerContext caching for ring signature optimization#48
Open
jorgecuesta wants to merge 1 commit intomainfrom
Open
perf: add SignerContext caching for ring signature optimization#48jorgecuesta wants to merge 1 commit intomainfrom
jorgecuesta wants to merge 1 commit intomainfrom
Conversation
- Add signerContextCache (sync.Map) to Signer struct to cache SignerContext instances per ring - Implement getOrCreateSignerContext() for thread-safe cache access - Update Sign() to use ring-go's SignWithContext() with cached context - Add ClearSignerContextCache() for session rollover cleanup - Update ring-go dependency to include SignerContext optimization This optimization avoids redundant cryptographic operations (ScalarBaseMul, hashToCurve, key image computation) when signing multiple requests with the same ring within a session. Benchmark improvements (ring-go): - Ring size 2: ~17.4% faster - Ring size 4: ~12.6% faster - Ring size 8: ~5.7% faster
8c5d637 to
1fca845
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
signerContextCache(sync.Map) toSignerstruct to cacheSignerContextinstances per ringgetOrCreateSignerContext()for thread-safe cache accessSign()to use ring-go'sSignWithContext()with cached contextClearSignerContextCache()for session rollover cleanupProblem
Ring signatures consume significant CPU time when signing relay requests. The existing implementation recomputes expensive cryptographic operations (ScalarBaseMul, hashToCurve, key image) on every sign call, even when using the same ring within a session.
Solution
Cache the pre-computed
SignerContextper ring. Since rings are tied to sessions (samesessionEndHeight= same ring), this cache is highly effective for the typical use case of signing multiple requests within the same session.Benchmark Results (ring-go)
Usage Note
Callers should invoke
ClearSignerContextCache()on session rollover to prevent unbounded cache growth.Test Plan